<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="referrer" content="no-referrer" />
    <title>好文网址</title>
  </head>

  <body>
    <div id="mainPanel" class="mainPanel"></div>

    <script type="text/javascript">
      var panelDataArr = [
        //**********
        {
          "#title": "开发框架学习",
          "极速开发框架-Ruoyi": "https://zhuanlan.zhihu.com/p/484074325",
        },
        //**********
      ];

      window.onload = function () {
        refresh("mainPanel", panelDataArr);
      };
    </script>

<script type="text/javascript">
  function refresh(elId, panelDatas) {
    //*************************
    console.log(panelDatas);
    var mainPanel = document.getElementById(elId);
    for (var idx in panelDatas) {
      var panelData = panelDatas[idx];
      var panDom = parseDom("<div class='itemPanel'></div>");

      const title = panelData["#title"]
      if (title) {
        title2Dom[title] = panDom
        panDom.appendChild(
          parseDom(`<div class='panTitle' onclick='shiftPut("${title}")'>${title} <i class='panPutIcon'></i></div>`)
        );
      }

      for (var name in panelData) {
        const value = panelData[name]
        if (name == "#title") {
          continue
        }
        if (name == "#sub" || name.indexOf("#sub-") >= 0) {
          panDom.appendChild(
            parseDom("<p class='subTitle'>--- " + value + "</p>")
          );
        } else {
          const info = typeof value == "string" ? { url: value } : value;
          panDom.appendChild(
            parseDom(
              `<a href= '${info.url}' title='${info.hint || ""
              }'  target='_blank' class='link'>${name}</a>`
            )
          );
        }
      }
      mainPanel.appendChild(panDom);
    }
    refreshPut()
  }

  const title2Dom = {}
  const putUpInfo = JSON.parse(localStorage.getItem("putUpInfo") || '{}')
  function refreshPut() {
    for (let title in putUpInfo) {
      const dom = title2Dom[title]
      if (!dom) continue
      putUpInfo[title] ? dom.setAttribute('putUp', '') : dom.removeAttribute('putUp');
    }
  }
  function shiftPut(title) {
    putUpInfo[title] = !putUpInfo[title]
    refreshPut()
    localStorage.setItem("putUpInfo", JSON.stringify(putUpInfo))
  }

  function parseDom(htmlText) {
    var objE = document.createElement("div");
    //去除头尾空格，防止空格成为节点
    htmlText =
      htmlText == null ? "" : htmlText.replace(/(^\s*)|(\s*$)/g, "");
    objE.innerHTML = htmlText;
    return objE.childNodes[0];
  }

</script>

<style>
  body {
    position: absolute;
    width: 100%;
    height: 100%;
    margin: 0;
    display: flex;
  }

  .mainPanel {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    margin-left: 30px;
    margin-right: 10px;
    margin-top: 20px;
    margin-bottom: 20px;
    min-height: 1000px;
  }

  .itemPanel {
    width: 300px;
    min-height: 20px;
    margin: 12px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
  }

  .panTitle {
    position: relative;
    text-align: center;
    font-size: 18px;
    margin: 0;
    color: #551a88;
    cursor: pointer;
    user-select:none;
  }

  .panPutIcon {
    position: absolute;
    right: 0;
    top: 0;
  }

  .panPutIcon::after {
    content: "↓";
    position: absolute;
    right: 0;
    top: -5px;
    font-size: 20px;
    padding: 0 0 15px 15px;
  }

  .subTitle {
    font-size: 14px;
    margin: 8px 10px 8px 0px;
    color: gray;
  }

  .link {
    text-decoration: none;
    margin: 8px 10px 8px 15px;
    font-size: 16px;
  }


  .itemPanel[putUp] .subTitle,
  .itemPanel[putUp] .link {
    display: none;
  }

  .itemPanel[putUp] .panPutIcon::after {
    content: "↑";
  }
</style>
</body>

</html>